package com.localjoycommunity.cpdj.project.system.controller;

import com.localjoycommunity.cpdj.common.utils.file.FileUploadUtils;
import com.localjoycommunity.cpdj.framework.config.TwoNewPartyConfig;
import com.localjoycommunity.cpdj.framework.web.domain.AjaxResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/** @Author: lida @Date: 2020/11/12 0012 上午 8:43 @Description: 图片视频上传 */
@RestController
@RequestMapping("/system/user/")
public class UploadController {

  /** 图片视频上传 */
  @PostMapping("/upload")
  public AjaxResult avatar(@RequestParam("file") MultipartFile file) throws IOException {
    if (!file.isEmpty()) {
      String fileName = FileUploadUtils.upload(TwoNewPartyConfig.getUploadPath(), file);
      AjaxResult ajax = AjaxResult.success();
      ajax.put("url", fileName);
      return ajax;
    }
    return AjaxResult.error("上传异常，请联系管理员");
  }
}